package com.atguigu.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author zhangchunsheng
 * @CreateTime: 2025/01/20
 */
@Component("myInterceptor1")
public class MyInterceptor1 implements HandlerInterceptor {

    /**
    * @Author: zhangchunsheng
    * @Date: 2025/1/20 11:29
     * 执行Controller之前
    */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("===>MyInterceptor111->preHandle()!!!");
        return true;
    }

    /**
    * @Author: zhangchunsheng
    * @Date: 2025/1/20 11:29
     * 执行Controller之后，渲染视图之前
    */
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        System.out.println("===>MyInterceptor111->postHandle()!!!");
    }

    /**
    * @Author: zhangchunsheng
    * @Date: 2025/1/20 11:29
     * 最后执行
        响应数据之后
        响应视图之后
    */
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        System.out.println("===>MyInterceptor111->afterCompletion()!!!");
    }

}
